﻿<navigation:PageView x:Class="Corina.Cydee.Apphub.Views.Sysmgr.ManagerView"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                     xmlns:localViewmodel="clr-namespace:Corina.Cydee.Apphub.Viewmodels"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                     xmlns:navigation="clr-namespace:Corina.Cydee.Apphub.Base"
                     xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                     xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
                     Title="账户管理"
                     d:DesignHeight="480"
                     d:DesignWidth="640"
                     mc:Ignorable="d">
    <navigation:PageView.DataContext>
        <localViewmodel:ManagerViewmodel />
    </navigation:PageView.DataContext>
    <Grid x:Name="LayoutRoot" Margin="6">
        <Grid Visibility="{Binding ShowUpdate, Converter={StaticResource BooleanToVisibilityInverseConverter}}">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="auto" />
                </Grid.ColumnDefinitions>

                <sdk:Label VerticalAlignment="Center" Content="关键字：" />

                <TextBox Grid.Column="1"
                         Width="300"
                         HorizontalAlignment="Left"
                         Text="{Binding Keywords,
                                        Mode=TwoWay,
                                        UpdateSourceTrigger=PropertyChanged}" />

                <Button Grid.Column="2"
                        Command="{Binding InsertCommand}"
                        Content="新建管理员" />

            </Grid>

            <toolkit:BusyIndicator Grid.Row="1"
                                   BusyContent="正在加载数据，请稍后..."
                                   IsBusy="{Binding IsBusy}">
                <sdk:DataGrid Margin="0,12,0,0"
                              AutoGenerateColumns="False"
                              ColumnWidth="*"
                              IsReadOnly="True"
                              ItemsSource="{Binding DisplayCollection}">
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTextColumn MinWidth="150"
                                                Binding="{Binding Account}"
                                                Header="帐号" />
                        <sdk:DataGridTextColumn MinWidth="150"
                                                Binding="{Binding Name}"
                                                Header="姓名" />
                        <sdk:DataGridTextColumn MinWidth="200"
                                                Binding="{Binding RegisterTime,
                                                                  StringFormat=\{0:yyyy-MM-dd HH:mm:ss tt\}}"
                                                Header="注册时间" />
                        <sdk:DataGridTextColumn MinWidth="150"
                                                Binding="{Binding Role}"
                                                Header="角色" />
                        <sdk:DataGridTextColumn MinWidth="150"
                                                Binding="{Binding AccountStatus,
                                                                  Converter={StaticResource EnumTranslationConverter},
                                                                  ConverterParameter=ACCOUNTSTATUS}"
                                                Header="状态" />
                        <sdk:DataGridTemplateColumn MinWidth="150" Header="操作">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel VerticalAlignment="Center" Orientation="Horizontal">
                                        <HyperlinkButton Content="锁定" Visibility="{Binding AccountStatus, Converter={StaticResource EuqalsToVisibilityConverter}, ConverterParameter=Normal}">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.BlockCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                        <HyperlinkButton Content="解除" Visibility="{Binding AccountStatus, Converter={StaticResource EuqalsToVisibilityConverter}, ConverterParameter=Block}">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.UnblockCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                        <HyperlinkButton Margin="12,0" Content="删除">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                    </StackPanel>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>
            </toolkit:BusyIndicator>

        </Grid>

        <Grid Visibility="{Binding ShowUpdate, Converter={StaticResource BooleanToVisibilityConverter}}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <StackPanel>
                    <TextBlock Text="帐号" />
                    <TextBox Text="{Binding UpdateEntity.Account, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    <TextBlock Margin="0,12,0,0" Text="姓名" />
                    <TextBox Text="{Binding UpdateEntity.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    <TextBlock Margin="0,12,0,0" Text="密码" />
                    <PasswordBox Password="{Binding UpdateEntity.Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource PasswordBoxStyle}" />
                    <TextBlock Margin="0,12,0,0" Text="确认密码" />
                    <PasswordBox Password="{Binding ConfirmPassword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource PasswordBoxStyle}" />
                    <TextBlock Foreground="Red"
                               Text="两次输入的密码不匹配"
                               Visibility="{Binding MatchPassword,
                                                    Converter={StaticResource BooleanToVisibilityInverseConverter}}" />
                    <TextBlock Margin="0,12,0,0" Text="电话" />
                    <TextBox Text="{Binding UpdateEntity.Mobile, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    <TextBlock Margin="0,12,0,0" Text="电子邮件" />
                    <TextBox Text="{Binding UpdateEntity.Email, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    <TextBlock Margin="0,12,0,0" Text="账户角色" />
                    <ComboBox ItemsSource="{Binding RolesCollection}" SelectedItem="{Binding SelectedRole, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Name}" />
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                </StackPanel>
                <StackPanel Grid.Row="1" Orientation="Horizontal">
                    <Button Width="60"
                            Margin="12,0"
                            Command="{Binding SubmitCommand}"
                            Content="提交" />
                    <Button Width="60"
                            Margin="12,0"
                            Command="{Binding CancelCommand}"
                            Content="取消" />
                </StackPanel>
            </Grid>
        </Grid>
    </Grid>
</navigation:PageView>
